<% layout('/layouts/default.html', {title: '车架号修改', libs: ['dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header">
			<div class="box-title">
				<i class="fa icon-notebook"></i> ${text('车架号修改')}
			</div>
		</div>
		<div class="box-body">
			<#form:form id="searchForm" model="${serviceOrder}" action="${ctx}/logistics/updatecarframenumber/updateCarFrameNumberListData" method="post" class="form-inline"
					data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize}" data-order-by="${parameter.orderBy}">
				<div class="form-group">
					<label class="control-label">${text('订单编号')}：</label>
					<div class="control-inline">
						<#form:input path="serviceOrderId" maxlength="100" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('订单状态')}：</label>
					<div class="control-inline width-120">
						<#form:select path="orderStatus" dictType="order_status" blankOption="true" class="form-control"/>
					</div>
				</div>
                <div class="form-group">
                    <label class="control-label">${text('客户')}：</label>
                    <div class="control-inline width-120">
                        <#form:treeselect id="customer" title="${text('客户选择')}"
                        path="customer.customerId" labelPath="customer.customerName"
                        url="${ctx}/base/customer/customer/treeData" canSelectRoot="true" canSelectParent="true"
                        class=" required" allowClear="true"/>
                    </div>
                </div>
				<div class="form-group">
					<label class="control-label">${text('车辆名称')}：</label>
					<div class="control-inline width-120">
                        <#form:input path="carName" maxlength="100" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('车架号')}：</label>
					<div class="control-inline width-120">
                        <#form:input path="frameNumber" maxlength="100" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('创建时间')}：</label>
					<div class="control-inline">
						<#form:input path="createDateGte" readonly="true" maxlength="20" class="form-control laydate width-datetime"
							dataFormat="datetime" data-type="datetime" data-format="yyyy-MM-dd HH:mm" data-done="createDate_lte.click()"/>
						&nbsp;-&nbsp;
						<#form:input path="createDateLte" readonly="true" maxlength="20" class="form-control laydate width-datetime"
							dataFormat="datetime" data-type="datetime" data-format="yyyy-MM-dd HH:mm"/>
					</div>
				</div>
				<div class="form-group">
					<button type="submit" id="searchButton" class="btn btn-primary btn-sm">${text('查询')}</button>
					<button type="reset" class="btn btn-default btn-sm">${text('重置')}</button>
				</div>
                <div class="form-unit">${text('车辆信息')} &nbsp;&nbsp;&nbsp;&nbsp;<button type="button" id="updateFrameNumber" class="btn btn-primary btn-sm">${text('更新  ')}</button></div>
			</#form:form>
			<table id="dataGrid"></table>
			<div id="dataGridPage"></div>
		</div>
	</div>
</div>
<% } %>
<script>
// 初始化DataGrid对象
$('#dataGrid').dataGrid({
	searchForm: $("#searchForm"),
	columnModel: [
		{header:'${text("车架号")}', name:'frameNumber', index:'b.frame_number', width:150, align:"center"},
		{header:'${text("车辆名称")}', name:'carName', index:'b.car_id', width:150, align:"center"},
		{header:'${text("车架号改为")}', name:'frameNumberNew', index:'', width:150, align:"center", editable:true,edittype:'text', editoptions:{'class':'form-control digits'}}
    ],
    showCheckbox: true,  // 是否显示复选框
    editGrid: true,		// 是否是编辑表格
    multiSort: false,  // 是否支持多列排序
    editGridInitRowNum: 0,
    editGridInputFormListName: 'dataGrid', // 提交的数据列表名
    editGridInputFormListAttrs: 'frameNumber,frameNumberNew',
	// 加载成功后执行事件
	ajaxSuccess: function(data){
		
	}
});


$('#updateFrameNumber').click(function () {
    var ids = $('#dataGrid').dataGrid('getSelectRows');
    var frameNumberArr = [];
    for (var i = 0; i < ids.length ; i++) {
        $('#dataGrid').dataGrid('saveRow', ids[i], true);
        $("#dataGrid").dataGrid("restoreRow", ids[i]);
        var lineData = $('#dataGrid').dataGrid('getRowData', ids[i]);
        frameNumberArr.push({
            "oldName":lineData.frameNumber,
            "newName":lineData.frameNumberNew
        });
        $("#dataGrid").dataGrid("editRow", ids[i], {keys: true, focusField: true});
    }

    if (frameNumberArr.length<=0){
        js.alert("请勾选要修改的车辆信息！");
    }else {
        $.ajax({
            type: "POST",
            async : false,
            url : "${ctx}/logistics/updatecarframenumber/updateFrameNumber",
            data: {"frameNumberArr": JSON.stringify(frameNumberArr)},
            dataType:"json",
            success: function (result) {
                js.showMessage(result.message);
                if (result.result == 'true'){
                    $('#dataGrid').dataGrid('reloadGrid');
                }
            }
        });
    }


});





</script>